package top.pmwly.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.pmwly.common.constant.ReslutEnum;
import top.pmwly.common.execption.BaseException;
import top.pmwly.dao.mapper.SysRoleMapper;
import top.pmwly.dao.mapper.SysUserRoleMapper;
import top.pmwly.dao.pojo.SysRole;
import top.pmwly.dao.pojo.SysUserRole;
import top.pmwly.service.ISysRoleService;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 角色信息表 服务实现类
 * </p>
 *
 * @author Herther
 * @since 2021-09-21
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    @Resource
    private SysRoleMapper sysRoleMapper;


    /**
     * 根据用户id 获取角色
     * @param Id
     * @return
     */
    @Override
    public SysRole getRole(Long Id) {
        SysRole sysRoles = sysRoleMapper.selectRoleByUserId(Id);
        if (null == sysRoles){
            //如果没查找角色抛出异常
            throw new BaseException(ReslutEnum.FAIL_ROLE_ERROR);
        }
        return sysRoles;
    }
}
